package com.ygq.train.member.controller;

import com.ygq.train.common.aspect.LogAspect;
import com.ygq.train.common.resp.CommonResp;
import com.ygq.train.common.resp.MemberLoginResp;
import com.ygq.train.member.req.MemberLoginReq;
import com.ygq.train.member.req.MemberRegisterReq;
import com.ygq.train.member.req.MemberSendCodeReq;
import com.ygq.train.member.service.MemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController

public class MemberController {

    @Resource
    private MemberService memberService;

    @GetMapping("/getCounts")
    public CommonResp<Integer> getCount(){
        int count = memberService.count();
        CommonResp<Integer> commonResp =new CommonResp<>();
        commonResp.setContent(count);
        return commonResp;
    }


    @PostMapping("/register")
    public CommonResp<Long> register(@Valid @RequestBody MemberRegisterReq req){
        Long registerId = memberService.Register(req);
//        CommonResp<Long> commonResp =new CommonResp<>();
//        commonResp.setContent(registerId);
//        return commonResp;
        return new CommonResp<>(registerId);
    }

    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req){
        memberService.SendCode(req);
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req){
        MemberLoginResp login = memberService.Login(req);
        return new CommonResp<>(login);
    }
}
